﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace CIT.WMS
{
    class Bll_CheckUser
    {
        public static DataTable GetStorage()
        {
            var sqlcmd = @"select * from T_Bllb_Storage_tbs";

            return Utils.NMS.QueryDataTable(Utils.uContext, sqlcmd, new CIT.WMS.MESWcf.CmdParameter[0]);
        }

        public static DataTable GetStorageRegion()
        {
            var sqlcmd = @"select * from wms_T_StorageRegion";

            return Utils.NMS.QueryDataTable(Utils.uContext, sqlcmd, new CIT.WMS.MESWcf.CmdParameter[0]);
        }

        public static DataTable GetStorageRegionByUserId(string userId)
        {
            var sqlcmd = @"SELECT region.Region_SN as Storage_SN, region.Region_Name FROM [dbo].[wms_T_StorageRegion] region 
INNER JOIN [dbo].[wms_R_UserStorage] relation ON relation.Storage_SN = region.Region_SN And UserID='{0}'";
            sqlcmd = string.Format(sqlcmd, userId);
            return Utils.NMS.QueryDataTable(Utils.uContext, sqlcmd, new CIT.WMS.MESWcf.CmdParameter[0]);
        }


        public static DataTable GetUserInfo(string userId)
        {
            var sql = string.Format(@"SELECT * FROM sysdatuser WHERE UserID='{0}'", userId);
            var dt = Utils.NMS.GetDataTable(sql);

            return dt;
        }

        public static DataTable CheckUser(string userId, string password)
        {
            var sql = string.Format(@"SELECT * FROM sysdatuser WHERE UserID='{0}' and Password='{1}'", userId, password);
            var dt = Utils.NMS.GetDataTable(sql);

            return dt;
        }

        public static DataTable GetUserInfo(string userId, string regionName)
        {
            var sql = string.Format(@"SELECT su.* FROM sysdatuser su LEFT JOIN
dbo.wms_R_UserStorage us ON su.UserID=us.UserID
LEFT JOIN wms_T_StorageRegion sr ON us.Storage_SN=sr.Region_SN
WHERE su.UserID='{0}' AND sr.Region_Name='{1}'", userId, regionName);
            var dt = Utils.NMS.GetDataTable(sql);

            return dt;
        }

        public static DataTable Query(string varWhere)
        {
            string sqlcmd = string.Format(@"select a.*,b.Storage_Name from T_Bllb_StorageDoc_tbsd a left join T_Bllb_Storage_tbs b
                                            on a.Source_Storage =b.Storage_SN {0}", varWhere);
            return Utils.NMS.QueryDataTable(Utils.uContext, sqlcmd, new CIT.WMS.MESWcf.CmdParameter[0]);
        }
    }
}
